package com.ruoyi.abuwx.controller;

import com.ruoyi.abuwx.domain.AbuwxQuestionCategory;
import com.ruoyi.abuwx.domain.AbuwxQuestionChoice;
import com.ruoyi.abuwx.service.IAbuwxQuestionCategoryService;
import com.ruoyi.abuwx.service.IAbuwxQuestionChoiceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 题库单选题Controller
 * 
 * @author tang
 * @date 2022-07-02
 */
@RestController
@RequestMapping("/abuwx/AbuwxQuestionChoice")
public class AbuwxQuestionChoiceController extends BaseController
{
    @Autowired
    private IAbuwxQuestionChoiceService abuwxQuestionChoiceService;
    @Autowired
    private IAbuwxQuestionCategoryService abuwxQuestionCategoryService;

    /**
     * 查询题库管理列表
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:dome')")
    @GetMapping("/dome")
    public TableDataInfo dome(AbuwxQuestionCategory abuwxQuestionCategory){

        List<AbuwxQuestionCategory> list = abuwxQuestionCategoryService.selectAbuwxQuestionCategoryList(abuwxQuestionCategory);
        return getDataTable(list);
    }

    /**
     * 查询题库单选题列表
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:list')")
    @GetMapping("/list")
    public TableDataInfo list(AbuwxQuestionChoice abuwxQuestionChoice)
    {
        startPage();
        List<AbuwxQuestionChoice> list = abuwxQuestionChoiceService.selectAbuwxQuestionChoiceList(abuwxQuestionChoice);
        return getDataTable(list);
    }

    /**
     * 导出题库单选题列表
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:export')")
    @Log(title = "题库单选题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbuwxQuestionChoice abuwxQuestionChoice)
    {
        List<AbuwxQuestionChoice> list = abuwxQuestionChoiceService.selectAbuwxQuestionChoiceList(abuwxQuestionChoice);
        ExcelUtil<AbuwxQuestionChoice> util = new ExcelUtil<AbuwxQuestionChoice>(AbuwxQuestionChoice.class);
        util.exportExcel(response, list, "题库单选题数据");
    }

    /**
     * 获取题库单选题详细信息
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(abuwxQuestionChoiceService.selectAbuwxQuestionChoiceById(id));
    }

    /**
     * 获取题库单选题详细信息
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:quer')")
    @GetMapping(value = "/info/{id}")
    public AjaxResult getInf(@PathVariable("id") Long id)
    {
        return AjaxResult.success(abuwxQuestionChoiceService.selectAbuwxQuestionChoiceByIds(id));
    }


    /**
     * 新增题库单选题
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:add')")
    @Log(title = "题库单选题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AbuwxQuestionChoice abuwxQuestionChoice){

        return toAjax(abuwxQuestionChoiceService.insertAbuwxQuestionChoice(abuwxQuestionChoice));
    }

    /**
     * 修改题库单选题
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:edit')")
    @Log(title = "题库单选题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AbuwxQuestionChoice abuwxQuestionChoice)
    {
        return toAjax(abuwxQuestionChoiceService.updateAbuwxQuestionChoice(abuwxQuestionChoice));
    }

    /**
     * 删除题库单选题
     */
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:remove')")
    @Log(title = "题库单选题", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(abuwxQuestionChoiceService.deleteAbuwxQuestionChoiceByIds(ids));
    }


    /*
导入功能
 */
    @Log(title = "题库单选题", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('abuwx:AbuwxQuestionChoice:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<AbuwxQuestionChoice> util = new ExcelUtil<AbuwxQuestionChoice>(AbuwxQuestionChoice.class);
        List<AbuwxQuestionChoice> userList = util.importExcel(file.getInputStream());
        String name = getUsername();
        String message = abuwxQuestionChoiceService.importUser(userList, updateSupport);
        return AjaxResult.success(message);
    }
}
